package com.eascs.ticket.home.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.log.TraceLoggerConfig;
import com.eascs.common.assertion.util.AssertWarnUtils;
import com.eascs.site.view.BaseRestResult;
import com.eascs.ticket.common.controller.BaseActionRestController;
import com.eascs.ticket.home.service.SayHelloSevice;

@RestController
public class SayHelloController extends BaseActionRestController {

	@Reference
	private SayHelloSevice sayHelloSevice;

	@RequestMapping("/home/rest/sayHello/success")
	public BaseRestResult<String> sayHelloSuccess() {
		return BaseRestResult.buildRestResult(sayHelloSevice.sayHello(false));
	}

	@RequestMapping("/home/rest/sayHello/trackMaxTime/2000")
	@TraceLoggerConfig(trackMaxTime = 2000)
	public BaseRestResult<String> trackMaxTime2000() throws InterruptedException {
		Thread.sleep(4000);
		return BaseRestResult.buildRestResult(sayHelloSevice.sayHello(false));
	}

	@RequestMapping("/home/rest/sayHello/trackMaxTime/5000")
	@TraceLoggerConfig(trackMaxTime = 5000)
	public BaseRestResult<String> trackMaxTime5000() throws InterruptedException {
		Thread.sleep(4000);
		return BaseRestResult.buildRestResult(sayHelloSevice.sayHello(false));
	}

	@RequestMapping("/home/rest/sayHello/false")
	public BaseRestResult<String> sayHelloFalse() {
		return BaseRestResult.buildRestResult(sayHelloSevice.sayHello(true));
	}

	@RequestMapping("/home/rest/sayHello/exception")
	public BaseRestResult<String> sayHelloException() {
		AssertWarnUtils.assertTrue(false, "sayHelloException");
		return BaseRestResult.buildRestResult(sayHelloSevice.sayHello(true));
	}

}
